package com.blog.blog.common;

import java.time.LocalDateTime;

public class ApiBaseResponse<T> {
    private Integer code;
    private String message;
    private T data;
    private LocalDateTime timestamp = LocalDateTime.now();

    public static <T> ApiBaseResponse<T> success(T data) {
        ApiBaseResponse<T> r = new ApiBaseResponse<>();
        r.setCode(0);
        r.setMessage("OK");
        r.setData(data);
        return r;
    }

    public static <T> ApiBaseResponse<T> error(int code, String message) {
        ApiBaseResponse<T> r = new ApiBaseResponse<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }

    public ApiBaseResponse<T> withData(T data) {
        this.data = data;
        return this;
    }

    public Integer getCode() { return code; }
    public void setCode(Integer code) { this.code = code; }
    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }
    public T getData() { return data; }
    public void setData(T data) { this.data = data; }
    public LocalDateTime getTimestamp() { return timestamp; }
    public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
}


